package com.chester.eurekaconsumerfeignrabbitmq.controller;

import com.chester.eurekaconsumerfeignrabbitmq.client.HelloClient;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author chester7cheng
 */
@Slf4j
@RestController
@RequestMapping("/hello")
public class HelloController {
    @Autowired
    private HelloClient helloClient;

    @GetMapping("/{name}")
    public String name(@PathVariable("name") String name){
        return helloClient.hello(name);
    }

    /**
     * 用于验证断路器
     * @return
     */
    @GetMapping("/feign")

    public String feign(){
        return helloClient.feign();
    }

    /**
     * 用户验证gateway断路器
     */
    @SneakyThrows
    @GetMapping("/gateway/hystrix/circuit-breaker")
    public String circuitBreaker(){
        log.trace("/gateway/hystrix/circuit-breaker");
        TimeUnit.MINUTES.sleep(1);

        return helloClient.hello("chester7cheng");
    }
}
